package com.zhijian.wharf.controller.web;

import com.zhijian.response.annotation.Response;
import com.zhijian.wharf.annotation.LogOperation;
import com.zhijian.wharf.holder.CurrentWebUserHolder;
import com.zhijian.wharf.service.ServerRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 服务注册
 *
 * @author HCG
 * @version 1.0
 * @date 2024-08-07
 */
@Slf4j
@Controller
@Api(tags = "服务注册")
public class ServerRegisterController {

    @Autowired
    private ServerRegisterService serverRegisterService;

    /**
     * 注册
     *
     * @param moduleList
     * @return
     */
    @Response
    @PostMapping("/server/register")
    @ApiOperation("注册")
    @LogOperation("服务注册")
    public boolean register(@RequestBody List<Long> moduleList) {
        return serverRegisterService.register(CurrentWebUserHolder.getUser().getId(), moduleList);
    }

    /**
     * 获取当前用户的注册模块
     *
     * @return
     */
    @Response
    @GetMapping("/server/modules")
    @ApiOperation("获取当前用户的注册模块")
    @LogOperation("获取当前用户的注册模块")
    public List<Integer> selectModules() {
        return serverRegisterService.selectModules(CurrentWebUserHolder.getUser().getId());
    }
}
